package com.wd.home.adapter

import android.R.attr.animateOnClick
import android.R.attr.data
import android.R.attr.onClick
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.wd.common.bean.NearbyChargeStationBean
import com.wd.home.R
import com.wd.home.callback.OnBack


class ChargeAdapter(private val context: Context, private val list: NearbyChargeStationBean, private var callback : OnBack ):
    RecyclerView.Adapter<ChargeAdapter.ViewHolder>(){

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflater= LayoutInflater.from(context).inflate(R.layout.item_charge,parent,false)
        return ViewHolder(inflater)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        Glide.with(context)
            .load(list.result[position].imageUrl)
            .placeholder(R.mipmap.ic_launcher_round)
            .error(R.mipmap.ic_launcher_round)
            .into(holder.charge_img)
        holder.charge_name.setText(list.result[position].name)
        holder.charge_price.setText("￥：\\"+list.result[position].price)
        holder.charge_wa.setText(""+list.result[position].wattage.toString())
        holder.itemView.setOnClickListener {
            list.result[position].location?.let { it1 -> list.result[position].name?.let { it2 ->
                callback.onClick(it1,
                    it2
                )
            } }
        }
        holder.charge_qu.setOnClickListener {
            list.result[position].location?.let { it2 -> callback.tomap(it2) }
        }

    }


    override fun getItemCount()=list.result.size

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val charge_img : ImageView
        val charge_qu : ImageView
        val charge_name : TextView
        val charge_wa : TextView
        val charge_price : TextView
        init {
            charge_img = itemView.findViewById(R.id.charge_img)
            charge_qu = itemView.findViewById(R.id.charge_qu)
            charge_name = itemView.findViewById(R.id.charge_name)
            charge_wa = itemView.findViewById(R.id.charge_wa)
            charge_price = itemView.findViewById(R.id.charge_price)
        }
    }


}